<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文章发布</title>
<link rel="shortcut icon" href="favicon.ico">

<link href="hmp/css/font-awesome.css?v=4.4.0" rel="stylesheet">
<link href="hmp/css/animate.css" rel="stylesheet">
<link href="hmp/css/style.css?v=4.1.0" rel="stylesheet">
<link href="hmp/layui/layui/css/layui.css" rel="stylesheet">
<link href="hmp/editor.md-master/css/editormd.css" rel="stylesheet">

</head>
<body class="gray-bg">
	<!--第一层  数据展示 -->
	<div class="wrapper wrapper-content animated fadeInRight">
		<!-- Panel Other -->
		<div class="ibox float-e-margins">
			<div class="ibox-content">
				<div class="row row-lg">
					<!-- Example Events -->
					<div class="example-wrap">
						<div class="example">
							<form class="layui-form" action="">
								<div class="layui-form-item">
									<label class="layui-form-label">文章标题</label>
									<div class="layui-input-block">
										<input type="text" name="title" id="title" required lay-verify="required"
											placeholder="请输入标题" autocomplete="off" class="layui-input">
									</div>
								</div>
								
								 
							   <div class="layui-form-item">
									<label class="layui-form-label">图标上传</label>
									 <button type="button" class="layui-btn" id="test1">
										  <i class="layui-icon">&#xe67c;</i>上传图片
									 </button>
									   <img class="layui-upload-img" id="demo1" style="width:10%;height:10%">
   									 <p id="demoText" name="demoText"></p>
   									 <input type="hidden" name="pic" id="pic">
								</div>
							 
								
								<div class="layui-form-item">
									<label class="layui-form-label">文章类型</label>
									<div class="layui-input-block radioType">
									</div>
								</div>

								<!-- MarkDown的id标志 -->
								<div id="my-editormd">
								  	  <textarea id="my-editormd-markdown-doc" name="my-editormd-markdown-doc" style="display:none;"></textarea>
								  	  <!-- 注意：name属性的值--> 
								  	  <textarea id="my-editormd-html-code" name="my-editormd-html-code" style="display:none;"></textarea>
							 	</div>

								<div class="layui-form-item">
									<label class="layui-form-label">选择标签</label>
									<div class="layui-input-block tags">
									 
									 </div>
								</div>
								<div class="layui-form-item">
									<div class="layui-input-block">
										<button class="layui-btn" lay-submit lay-filter="activeForm">立即提交</button>
										<button type="reset" class="layui-btn layui-btn-primary">重置</button>
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- 底层  占个坑  -->
	<div></div>

</body>

<!-- 全局js -->
<script src="hmp/js/jquery.min.js"></script>
<script src="hmp/js/bootstrap.min.js?v=3.3.6"></script>
<!-- 自定义js -->
<script src="hmp/js/content.js?v=1.0.0"></script>
<script src="hmp/layui/layui/layui.js"></script>
<script src="hmp/editor.md-master/editormd.min.js"></script>


<script>

 var content;

	$(function() {
	
		content=editormd("my-editormd", { //注意1：这里的就是上面的DIV的id属性值
	        width: "95%",
	        height: 640,
	        syncScrolling: "single",
	        path: "/hmp/editor.md-master/lib/", //注意2：你的路径
	        syncScrolling: "single",
	        imageUpload: true,
	        imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
	        imageUploadURL: "/file",
	        //下面这一行将使用dark主题
	       // previewTheme : "dark"
	    });
	    
	});

     	layui.use(['form','layer','upload'], function(){
		     var layer = layui.layer;
		  	var form = layui.form;
		 	 var upload = layui.upload;
		  
		  //监听提交
		  form.on('submit(activeForm)', function(data){
		    $.post("/active/save",data.field,function(result){
		    	
		    	 console.log(data.field);
		    	  
		    		if(result.code==200)
		    		{
		    			layer.alert(result.msg);
		    		}else
		    		{
		    			layer.alert(result.msg);
		    		}
		    });
		    return false;
		  });
		  
		  
			//执行实例
			  var uploadInst = upload.render({
			    elem: '#test1' //绑定元素
			    ,url: '/upload/picUpload' //上传接口
			    ,accept:'images'
			   // ,auto: false
			    ,before: function(obj){
			    	      //预读本地文件示例，不支持ie8
			    	 obj.preview(function(index, file, result){
			    		 
			    	        $('#demo1').attr('src', result); //图片链接（base64）
			    	  });
			    }
			    ,done: function(res){
			    	$('#pic').val(res.data); //后台新建的 名称 
			    	layer.alert(res.msg);
			    }
			    ,error: function(){
			    	layer.alert("请求异常回调");
			    }
			  });
		  
		
     	});
     	
     	
     	
     	
</script>


<script type="text/javascript">
	
	$(function(){
		  //得到所有的类型 
	    $.ajax({
	    	type : "POST",
	    	url : "/activeType/selectAll",
	    	//data :"",
	    	 async: false,  //加了这个属性，
	    	error : function(request) {
				laryer.alert("网络错误!");
			}, 
			success : function(data) {
				if (data.code ==200) {
					//拼接 html   
					var tag=data.data;
					var html='';
					for(var i=0;i<tag.length;i++)
					{
						if(i==0)
						{
							html+='<input type="radio" name="type" value="'+tag[i].activeTypeId+'" title="'+tag[i].typeName+'" checked="checked">';
						}else{
							
							html+='<input type="radio" name="type" value="'+tag[i].activeTypeId+'" title="'+tag[i].typeName+'"  >';
						
						}
					}
					$(".radioType").html(html);
					
				} else {
					laryer.alert("标签查询失败,请联系管理员")
				}
			}

	    });
		
	    
	    
	    //得到所有的标签
	    $.ajax({
	    	type : "POST",
	    	url : "/activeTag/selectAll",
	    	data :"",
	    	 async: false,  //加了这个属性，
	    	error : function(request) {
				laryer.alert("网络错误!");
			},
			success : function(data) {
				if (data.code ==200) {
					//拼接 html 
					var tag=data.data;
					var html='';
					for(var i=0;i<tag.length;i++)
					{
						html+='<input type="checkbox" name="tag['+tag[i].tagName+']" value="'+tag[i].tagName+'" title="'+tag[i].tagName+'">';
					}
					$(".tags").html(html);
					
				} else {
					laryer.alert("标签查询失败,请联系管理员")
				}
			}

	    });
	  
		
		
	}) 

</script>

</html>
